package remato.domain.server.ejb;

import static javax.persistence.CascadeType.ALL;
import static javax.persistence.GenerationType.AUTO;

import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.MapKey;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

import com.wgo.bpot.domain.common.User;

import remato.domain.common.Requirement;
import remato.domain.common.Stakeholder;
import remato.domain.common.impl.StakeholderImpl;

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class StakeholderEjb extends StakeholderImpl implements Stakeholder{

	@Override
	@Id
	@GeneratedValue(strategy=AUTO)
	public Long getDbId() {
		return super.getDbId();
	}

	@Override
	public String getFirstName() {
		return super.getFirstName();
	}

	@Override
	public String getLastName() {
		return super.getLastName();
	}
	
	@Override
	@Lob
	public String getDescription() {
		return super.getDescription();
	}

	@Override
	@OneToMany(mappedBy="persistableAssignedTo", targetEntity=RequirementEjb.class, cascade={ALL})
	@MapKey(name="dbId")
	public Set<Requirement> getAssignedRequirements() {
		return super.getAssignedRequirements();
	}

	@Override
	@OneToMany(mappedBy="persistableReporterOrOwner", targetEntity=RequirementEjb.class, cascade={ALL})
	@MapKey(name="dbId")
	public Set<Requirement> getReporterOrOwnerToRequirements() {
		return super.getReporterOrOwnerToRequirements();
	}

	@Override
	@ManyToMany(
			cascade={ALL},
			mappedBy="stakeholders",
			targetEntity=RequirementEjb.class
	)
	public Set<Requirement> getStakeholderToRequirements() {
		return super.getStakeholderToRequirements();
	}

	@Override
	@OneToOne(targetEntity=RequirementEjb.class, cascade={ALL})
	public User getUser() {
		return super.getUser();
	}

	/**
	 * Needed to trigger CGLib proxy (ie. if other CGLib-proxies is used as 
	 * parameter.)
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		return super.equals(obj);
	}

}
